Skip to content

Fix overriding a Java method with varargs #2076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2017

Conversation

smarter
Copy link
Member

@smarter smarter commented Mar 11, 2017

If A method like:

  override def foo(x: Object*)

overrides a Java method, it needs to be rewritten as:

  def foo(x: Seq[Object])
  override def foo(x: Array[Object]): Object = foo(Predef.wrapRefArray(x))

This should be handled by ElimRepeated but there were two bugs:

  • addVarArgsBridge was called at phase thisTransformer.next, this is
    too late to create the bridge since T* has already been rewritten as
    Seq[T]
  • The original method symbol needs to have the override flag dropped,
    since it doesn't override anything.

Furthermore, RefChecks had to be moved after ElimRepeated, otherwise
the testcase would fail the overriding checks.


@odersky I'm not sure if moving RefChecks is the best solution here. Alternatively we could teach TypeComparer about repeated params when we compare MethodTypes in a phase before ElimRepeated.

@smarter smarter requested a review from odersky March 11, 2017 15:41
@smarter
Copy link
Member Author

smarter commented Mar 12, 2017

Oops, I forgot to add the testcase, I'll amend the commit.

If A method like:
  override def foo(x: Object*)
overrides a Java method, it needs to be rewritten as:
  def foo(x: Seq[Object])
  override def foo(x: Array[Object]): Object = foo(Predef.wrapRefArray(x))

This should be handled by ElimRepeated but there were two bugs:
- `addVarArgsBridge` was called at phase `thisTransformer.next`, this is
too late to create the bridge since `T*` has already been rewritten as
`Seq[T]`
- The original method symbol needs to have the `override` flag dropped,
since it doesn't override anything.

Furthermore, RefChecks had to be moved after ElimRepeated, otherwise the
testcase would fail the overriding checks.
@smarter smarter force-pushed the fix/override-java-varargs branch from c26d2fc to e5e691e Compare March 12, 2017 12:28
This was a mistake introduced in the previous commit, installAfter is
only safe to use in `IdentityDenotTransformer` phases, otherwise it
means that the phase denotation transformer is not run at all for this
particular denotation, this caused Ycheck to fail.
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I think this is much better than burdening TypeComparer with the distinction of different implementations of varargs methods.

@odersky odersky merged commit a886727 into scala:master Mar 12, 2017
smarter added a commit to dotty-staging/dotty that referenced this pull request Mar 12, 2017
This wasn't done before because dotty could not compile dottydoc, this
got fixed by PRs scala#2070 and scala#2076.
smarter added a commit to dotty-staging/dotty that referenced this pull request Mar 12, 2017
This wasn't done before because dotty could not compile dottydoc, this
got fixed by PRs scala#2070 and scala#2076.
smarter added a commit to dotty-staging/dotty that referenced this pull request Mar 13, 2017
This wasn't done before because dotty could not compile dottydoc, this
got fixed by PRs scala#2070 and scala#2076.
smarter added a commit to dotty-staging/dotty that referenced this pull request Mar 13, 2017
This wasn't done before because dotty could not compile dottydoc, this
got fixed by PRs scala#2070 and scala#2076, and the previous commit fixed a
miscompilation issue.
smarter added a commit to dotty-staging/dotty that referenced this pull request Mar 14, 2017
This wasn't done before because dotty could not compile dottydoc, this
got fixed by PRs scala#2070 and scala#2076, and the previous commit fixed a
miscompilation issue.
smarter added a commit to dotty-staging/dotty that referenced this pull request Mar 15, 2017
This wasn't done before because dotty could not compile dottydoc, this
got fixed by PRs scala#2070 and scala#2076, and the previous commit fixed a
miscompilation issue.
smarter added a commit to dotty-staging/dotty that referenced this pull request Mar 15, 2017
This wasn't done before because dotty could not compile dottydoc, this
got fixed by PRs scala#2070 and scala#2076, and the previous commit fixed a
miscompilation issue.
smarter added a commit to dotty-staging/dotty that referenced this pull request Mar 15, 2017
This wasn't done before because dotty could not compile dottydoc, this
got fixed by PRs scala#2070 and scala#2076, and the previous commit fixed a
miscompilation issue.
smarter added a commit to dotty-staging/dotty that referenced this pull request Mar 16, 2017
This wasn't done before because dotty could not compile dottydoc, this
got fixed by PRs scala#2070 and scala#2076, and the previous commit fixed a
miscompilation issue.
@allanrenucci allanrenucci deleted the fix/override-java-varargs branch December 14, 2017 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants